package com.cskaoyan.wxcontroller;

import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.domain.Goods;
import com.cskaoyan.bean.domain.User;
import com.cskaoyan.bean.goods.BasePageData;
import com.cskaoyan.bean.goods.GoodsDetailVo;
import com.cskaoyan.bean.goods.smallVo.UserOrderInfoVo;
import com.cskaoyan.bean.goods.wechat.CategoryList;
import com.cskaoyan.bean.goods.wechat.CategorySearchBean;
import com.cskaoyan.bean.goods.wechat.CategoryVo;
import com.cskaoyan.bean.goods.wechat.UserOrderVo;
import com.cskaoyan.service.WxUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongProject: mall35th
 * @BelongPackage: com.cskaoyan.wxcontroller
 * @Author: zijin
 * @Createtime: 2021-12-03 星期五 14:11
 * @Description: todo
 */
@RestController
public class WxUserController {
    @Autowired
    WxUserService userService;

    /**
     * 从订单表中查询数据需要返回待付款、待发货、待收货、待评价
     * @return
     */
    @RequestMapping("/wx/user/index")
    public BaseRespVo index(){
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()){
            User user = (User) subject.getPrincipals().getPrimaryPrincipal();
            UserOrderVo userOrderVo = userService.queryUserOrderMessage(user.getId());
            UserOrderInfoVo userOrderInfoVo = new UserOrderInfoVo();
            userOrderInfoVo.setOrder(userOrderVo);
            return BaseRespVo.ok(userOrderInfoVo);
        }
        return BaseRespVo.ok(null);
    }

    /**
     * http://182.92.235.201:8083/wx/goods/detail?id=1116011
     * 根据商品id查询商品详情
     */

    @RequestMapping("/wx/goods/detail")
    public BaseRespVo detail(Integer id){
        GoodsDetailVo goodsDetailVo = userService.queryGoodsDatails(id);
        return BaseRespVo.ok(goodsDetailVo);
    }

    @RequestMapping("/wx/goods/count")
    public BaseRespVo count(){
        int num = userService.queryGoodsNum();
        return BaseRespVo.ok(num);
    }

    /**
     * http://182.92.235.201:8083/wx/goods/category?id=100500
     * @return
     */
    @RequestMapping("wx/goods/category")
    public BaseRespVo cateegory(Integer id){
        CategoryVo categoryVo = userService.queryCategory(id);
        return BaseRespVo.ok(categoryVo);
    }

    /**
     * http://localhost:8083/wx/goods/list?categoryId=1008002&page=1&limit=10
     */
    @RequestMapping("/wx/goods/list")
    public BaseRespVo list(CategorySearchBean categorySearchBean){
        CategoryList categoryList =userService.queryGoodsByCategory(categorySearchBean);
        return BaseRespVo.ok(categoryList);
    }

    /**
     * http://localhost:8083/wx/goods/related?id=1009012
     */
    @RequestMapping("/wx/goods/related")
    public BaseRespVo related(Integer id){
        BasePageData<Goods> basePageData = userService.searchRelated(id);
        return BaseRespVo.ok(basePageData);
    }

}
